import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class DropdownPage extends StatelessWidget {
  final SystemUiOverlayStyle _style =
      SystemUiOverlayStyle(statusBarColor: Colors.transparent);

  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(_style);
    // TODO: implement build
    return MaterialApp(
      home: DropdownWidget(),
      theme: ThemeData(primarySwatch: Colors.yellow),
    );
  }
}

class DropdownWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _DropdownPage();
  }
}

class _DropdownPage extends State<StatefulWidget> {
  String choosedValue = "";
  List<DropdownMenuItem> _listItems() {
    List<DropdownMenuItem> cityList = List<DropdownMenuItem>();
    cityList.add(DropdownMenuItem(
      child: Text("北京"),
      value: "beijing",
    ));
    cityList.add(DropdownMenuItem(
      child: Text("上海"),
      value: "shanghai",
    ));
    cityList.add(DropdownMenuItem(
      child: Text("广州"),
      value: "guangzhou",
    ));
    cityList.add(DropdownMenuItem(
      child: Text("深圳"),
      value: "shenzhen",
    ));
    return cityList;
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("Dropdown Page"),
      ),
      body: DropdownButton(
        value: choosedValue,
        items: _listItems(),
        onChanged: (value){
          setState(() {
            choosedValue = value;
          });
        },
        hint: Text("请选择城市"),
      ),
    );
  }
}
